package UILayer;
import java.util.Scanner;
import CtrlLayer.*;
import ModelLayer.Supplier;

public class SupplierUI
{
	private PersonCtrl PC;
	private Supplier mysupplier;
	
    public SupplierUI()
    {
    	PC = new PersonCtrl();
    }
    
    public void SupplierMenu()
    {   
    	boolean exit = false;
        while (!exit) //! means while exit not is true (that is: false)
        {
        	int choise = writeSupplyerMenu();
        	switch(choise)
        	{
        		case 1: addSupplier(); break;
    			case 2: delSupplier(); break;
    			case 3: getSupplierUI(); break;
    			case 4: listAllSupplier(); break;
        		case 99: exit = true; break;
        	}//end switch
        }//end while
    }
    
    private int writeSupplyerMenu()
    {
        //creates an object keyboard to read data from the keyboard
    	Scanner keyboard = new Scanner(System.in);
    	System.out.println(" *** Leverandoer Menu ***");
    	System.out.println(" (1) Opret Leverandoer");
    	System.out.println(" (2) Slet Leverandoer");
    	System.out.println(" (3) Find Leverandoer");
    	System.out.println(" (4) List alle Leverandoer");
    	System.out.println(" (99) Tilbage");
    	System.out.print("\n Make your choise: ");
    	int choise = keyboard.nextInt();
    	return choise;
    }
    
    public void addSupplier()
    { // String name, String address, String postal, String city, String phone, String email, String companyName, int creditornr
    	String name = inputtext("Kontakt Navn ");
    	String address = inputtext("Adresse ");
    	String postal = inputtext("Postnr ");
    	String city = inputtext("By ");
    	String phone = inputtext("Tlf ");
    	String email = inputtext("email ");
    	String companyName = inputtext("Firma navn ");
    	int creditornr = inputintnumber("Leverandoer nr ");
    	PC.createSupplier(name, address, postal, city, phone, email, companyName, creditornr);
    }
    
    public void delSupplier()
    {
    	
    }
    
    public void getSupplierUI()
    {
    	String phone = inputtext("Tlf ");
    	mysupplier = PC.searchSupplier(phone);
    	System.out.println( mysupplier.getName() );
    	System.out.println( mysupplier.getAddress() );
    	System.out.println( mysupplier.getPostal() + "  " + mysupplier.getCity() );
    	System.out.println( "tlf: " + mysupplier.getPhone() );
    	System.out.println( mysupplier.getEmail() );
    	System.out.println( mysupplier.getCompanyName() );
    	System.out.println( mysupplier.getCreditornr() );
    }
    
    public Supplier getSupplier(String phone)
    {
    	return PC.searchSupplier(phone);
    }
    
    public void listAllSupplier()
    {
    	
    }
    
    /**
     * Print a text and takes input from keyboard
     * @param text Print text
     * @return str Return the input from the keyboard 
     */
    private String inputtext(String text)
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.print(text + ": ");
        String str = keyboard.nextLine();
        return str;
    }
    
    private int inputintnumber(String text)
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.print(text + ": ");
        String str = keyboard.nextLine();
        int no = Integer.parseInt(str.trim());  // convert String 2 long
        return no;
    }
    
}